    <table class="table">
    <thead>
      <tr>
        <th colspan="2"><?php printf($this->_lang['stats_title'], $this->config['site_name'], strftime($this->config['date_format'], $startdate), strftime($this->config['date_format'], $enddate)); ?></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class='row3'><?php echo $this->_lang['page_impressions']; ?></td>
        <td class='row1' width="25%"><?php echo number_format($pitotal); ?></td>
      </tr>
      <tr>
        <td class='row3'><?php echo $this->_lang['visits']; ?></td>
        <td class='row1'><?php echo number_format($vitotal); ?></td>
      </tr>
      <tr>
        <td class='row3'><?php echo $this->_lang['visitors']; ?></td>
        <td class='row1'><?php echo number_format($vistotal); ?></td>
      </tr>
    </tbody>
  </table>

  <p style="text-align:center;">
    <input type="button" class="btn btn-default" name='clear_visitor_logs' value="<?php echo $this->_lang['empty_visitor_logs']; ?>" onclick="if(confirm('<?php echo $this->_lang['empty_visitor_logs_confirm']; ?>')==true) document.location.href='index.php?a=56';" /> Does not currently work
  </p>

  <?php

  switch($scope) {
    case "total" :
  ?>

  <!-- Monthly Stats -->
  <table class="table-striped table">
    <thead>
      <tr>
        <th colspan="7"><?php echo $this->_lang['stats_monthly_breakup']; ?></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class='row3' width="25%">&nbsp;</td>
        <td class='row3' width="25%" colspan="2"><b><?php echo $this->_lang['page_impressions']; ?></b></td>
        <td class='row3' width="25%" colspan="2"><b><?php echo $this->_lang['visits']; ?></b></td>
      </tr>
  <?php
  $startYear = date('Y', $startdate);
  $years = (date('Y', time())-$startYear)+1;
  $monthCount = 0;
  $firstResultsShown = 0;
  $maxResult = time(); // this is so we don't output anything for the future

  for($i=0; $i<(12*$years); $i++) {

    $monthStart = mktime(0,   0,  0, $i+1, 1, $startYear); // month start, the year will be incremented by the $i :)
    $monthEnd   = mktime(23, 59, 59, $i+1, date('t', $monthStart), $startYear); // month end, the year will be incremented by the $i :)

    // get page impressions for time period
    $sql = "SELECT COUNT(*) FROM ".$this->db."log_access WHERE timestamp > $monthStart AND timestamp < $monthEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $pi = $tmp['COUNT(*)'];

    // get visits for time period
    $sql = "SELECT COUNT(*) FROM ".$this->db."log_access WHERE entry='1' AND timestamp > $monthStart AND timestamp < $monthEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $vi = $tmp['COUNT(*)'];

    // get visitors for time period
    $sql = "SELECT COUNT(DISTINCT(visitor)) FROM ".$this->db."log_access WHERE timestamp > $monthStart AND timestamp < $monthEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $vis = $tmp['COUNT(DISTINCT(visitor))'];
    if(($vis>0 || $vi>0 || $pi>0 || $firstResultsShown>0) && $monthStart<$maxResult) {
      $firstResultsShown = 1; // this is so we don't show emtpy months where no logging was done before we've actually output anything.
  ?>
      <tr>
        <td class='row3' width="25%"><a href="javascript:;" onclick="Etomite.showVisitorStats('scope=month&start=<?php echo $monthStart; ?>');"><?php echo $this->_lang['months'][$monthCount]." ".date('Y', $monthStart); ?></a></td>
        <td class='row1' style="width:12.5%;"><?php echo $pi==0 ? "-" : number_format($pi); ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $pi==0 ? "-" : number_format(($pi/$pitotal)*100, 1)." %"; ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $vi==0 ? "-" : number_format($vi); ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $vi==0 ? "-" : number_format(($vi/$vitotal)*100, 1)." %"; ?></td>
      </tr>
  <?php
    }
    if($monthCount==11) {
      $monthCount = 0;
    } else {
      $monthCount += 1;
    }
  }
  ?>
    </tbody>
  </table>
  <?php
    break;
    case "month" :
  ?>

  <!-- Daily Stats -->
  <table class="table-striped table">
    <thead>
      <tr>
        <th colspan="5"><?php echo $this->_lang['stats_daily_breakup']; ?></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class='row3' width="25%">&nbsp;</td>
        <td class='row3' width="25%" colspan="2"><b><?php echo $this->_lang['page_impressions']; ?></b></td>
        <td class='row3' width="25%" colspan="2"><b><?php echo $this->_lang['visits']; ?></b></td>
      </tr>
  <?php
  $days = date('t', $startdate);
  $month = date('n', $startdate);
  for($i=0; $i<$days; $i++) {

    $dayStart = mktime(0,   0,  0, $month, $i+1, date('Y', $startdate)); // month start, the year will be incremented by the $i :)
    $dayEnd   = mktime(23, 59, 59, $month, $i+1, date('Y', $startdate)); // month end, the year will be incremented by the $i :)

    // get page impressions for time period
    $sql = "SELECT COUNT(*) FROM ".$this->db."log_access WHERE timestamp > $dayStart AND timestamp < $dayEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $pi = $tmp['COUNT(*)'];

    // get visits for time period
    $sql = "SELECT COUNT(*) FROM ".$this->db."log_access WHERE entry='1' AND timestamp > $dayStart AND timestamp < $dayEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $vi = $tmp['COUNT(*)'];

    // get visitors for time period
    $sql = "SELECT COUNT(DISTINCT(visitor)) FROM ".$this->db."log_access WHERE timestamp > $dayStart AND timestamp < $dayEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $vis = $tmp['COUNT(DISTINCT(visitor))'];
  ?>
      <tr>
        <td class='row3' width="25%"><a href="javascript:;" onclick="Etomite.showVisitorStats('scope=day&start=<?php echo $dayStart; ?>');"><?php echo $this->_lang['days'][date('w', $dayStart)]." ".strftime($date_format, $dayStart); ?></a></td>
        <td class='row1' style="width:12.5%;"><?php echo $pi==0 ? "-" : number_format($pi); ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $pi==0 ? "-" : number_format(($pi/$pitotal)*100, 1)." %"; ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $vi==0 ? "-" : number_format($vi); ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $vi==0 ? "-" : number_format(($vi/$vitotal)*100, 1)." %"; ?></td>
      </tr>
  <?php
  }
  ?>
    </tbody>
  </table>
  <?php
    break;
    case "day" :
  ?>

  <!-- Hourly Stats -->
  <table class="table-striped table">
    <thead>
      <tr>
        <td colspan="5"><b><?php echo $this->_lang['stats_hourly_breakup']; ?></b></td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class='row3' width="25%">&nbsp;</td>
        <td class='row3' width="25%" colspan="2"><b><?php echo $this->_lang['page_impressions']; ?></b></td>
        <td class='row3' width="25%" colspan="2"><b><?php echo $this->_lang['visits']; ?></b></td>
      </tr>
  <?php
  for($i=0; $i<24; $i++) {

    $hourStart = mktime($i,   0,  0, date('n', $startdate), date('d', $startdate), date('Y', $startdate)); // month start, the year will be incremented by the $i :)
    $hourEnd   = mktime($i, 59, 59, date('n', $startdate), date('d', $startdate), date('Y', $startdate)); // month end, the year will be incremented by the $i :)

    // get page impressions for time period
    $sql = "SELECT COUNT(*) FROM ".$this->db."log_access WHERE timestamp > $hourStart AND timestamp < $hourEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $pi = $tmp['COUNT(*)'];

    // get visits for time period
    $sql = "SELECT COUNT(*) FROM ".$this->db."log_access WHERE entry='1' AND timestamp > $hourStart AND timestamp < $hourEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $vi = $tmp['COUNT(*)'];

    // get visitors for time period
    $sql = "SELECT COUNT(DISTINCT(visitor)) FROM ".$this->db."log_access WHERE timestamp > $hourStart AND timestamp < $hourEnd ";
    $rs = $this->dbQuery($sql);
    $tmp = $this->fetchRow($rs);
    $vis = $tmp['COUNT(DISTINCT(visitor))'];

    $hour = strlen($i)==1 ? "0".$i : $i ;
  ?>
      <tr>
        <td class='row3' width="25%"><?php echo "$hour:00:00 - $hour:59:59"; ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $pi==0 ? "-" : number_format($pi); ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $pi==0 ? "-" : number_format(($pi/$pitotal)*100, 1)." %"; ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $vi==0 ? "-" : number_format($vi); ?></td>
        <td class='row1' style="width:12.5%;"><?php echo $vi==0 ? "-" : number_format(($vi/$vitotal)*100, 1)." %"; ?></td>
      </tr>
  <?php
  }
  ?>
    </tbody>
  </table>
<?php
  break;
}
?>